# Contributor: Mathias LANG <pro.mathias.lang@gmail.com>
# Maintainer: Mathias LANG <pro.mathias.lang@gmail.com>
pkgname=dub
pkgver=1.21.0
pkgrel=0
pkgdesc="Package and build management system for D"
url="http://code.dlang.org/"
arch="all !ppc64le !mips !mips64" # GDC does not support these architectures
license="MIT"
depends="libcurl"
makedepends="gcc-gdc gdmd bash curl-dev"
subpackages="$pkgname-zsh-completion:zsh:noarch $pkgname-doc:doc:noarch"
source="$pkgname-$pkgver.zip::https://github.com/dlang/dub/archive/v$pkgver.zip"

build() {
	DMD=gdmd GITVER="v$pkgver" gdmd -run "$builddir/build.d"

	# Build man pages
	"$builddir/bin/dub" scripts/man/gen_man.d
}

check() {
	bin/dub test
}

package() {
	install -s -D "$builddir/bin/dub" "$pkgdir/usr/bin/dub"
	install -Dm644 "$builddir/scripts/zsh-completion/_dub" "$pkgdir/usr/share/zsh/site-functions/_dub"
	mkdir -p "$pkgdir/usr/share/man/man1/"
	cp "$builddir"/scripts/man/*.1 "$pkgdir/usr/share/man/man1/"
}

zsh() {
	pkgdesc="Zsh completion for dub"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel zsh"

	mkdir -p "$subpkgdir"/usr/share/zsh/site-functions
	mv "$pkgdir"/usr/share/zsh/site-functions/* \
		"$subpkgdir"/usr/share/zsh/site-functions
	# Satisfy abuild's linter
	rmdir "$pkgdir"/usr/share/zsh/site-functions
}

doc() {
	pkgdesc="Man pages for dub"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel docs"

	gzip -9 "$pkgdir"/usr/share/man/man1/*
	mkdir -p "$subpkgdir"/usr/share/man/man1
	mv "$pkgdir"/usr/share/man/man1/* "$subpkgdir"/usr/share/man/man1/
	# Satisfy abuild's linter
	rmdir "$pkgdir"/usr/share/man/man1/
	rmdir "$pkgdir"/usr/share/man/
}

sha512sums="7144fb98bb994dba696ba004dd517ee3cc8639ab9e77898b27ae5af4e94d5715123356864eb56cebade2b9e591f2659a7782497c09f703c701765225e4883ed0  dub-1.21.0.zip"
